﻿using UnityEngine;
using System;
using System.Collections;

public class EffectController : BaseController
{

	private static EffectController _inst;

	public static EffectController inst { get { return _inst; } }

	public Transform _effectRoot;
	public Transform _shuziPrefab;
	public Transform _lianduiPrefab;
	public Transform _zhadanPrefab;

	protected override void InitData ()
	{
		base.InitData ();
		_inst = this;
	}

	public void PlayShunzi (Action callback = null)
	{
		DebugInfo.Log ("播放顺子特效");

		Transform effTrans = GameObject.Instantiate (_shuziPrefab);
		effTrans.SetParent (_effectRoot);
		effTrans.localPosition = Vector3.zero;
		TimerController.inst.CallAfter (2.0f, args => {
			effTrans.SetParent (null);
			GameObject.Destroy(effTrans.gameObject);
			if (callback != null)
				callback ();
		});
	}

	public void PlayLiandui (Action callback = null)
	{
		DebugInfo.Log ("播放连对特效");

		Transform effTrans = GameObject.Instantiate (_lianduiPrefab);
		effTrans.SetParent (_effectRoot);
		effTrans.localPosition = Vector3.zero;
		TimerController.inst.CallAfter (2.0f, args => {
			effTrans.SetParent (null);
			GameObject.Destroy(effTrans.gameObject);
			if (callback != null)
				callback ();
		});
	}

	public void PlayZhadan (Action callback = null)
	{
		DebugInfo.Log ("播放炸弹特效");

		/*GameObject effGo = Resources.Load<GameObject> ("effect/partical/doudizhu2/zhadan");
		effGo = Instantiate<GameObject>(effGo);
		effGo.transform.SetParent (_effectRoot);
		effGo.transform.localPosition = Vector3.zero;
		TimerController.inst.CallAfter (3.0f, args => {
			effGo.transform.SetParent (null);
			GameObject.Destroy(effGo);
			if (callback != null)
				callback ();
		});*/

		Transform effTrans = GameObject.Instantiate (_zhadanPrefab);
		effTrans.SetParent (_effectRoot);
		effTrans.localPosition = Vector3.zero;
		TimerController.inst.CallAfter (2.0f, args => {
			effTrans.SetParent (null);
			GameObject.Destroy(effTrans.gameObject);
			if (callback != null)
				callback ();
		});
	}

	public void PlayCardTypeEffect (int type, Action callback = null)
	{
		switch (type) {
		case GameEnum.CardType.TYPE_ORDER_PAIR:
			PlayLiandui (callback);
			break;
		case GameEnum.CardType.TYPE_ORDER:
			PlayShunzi (callback);
			break;
		case GameEnum.CardType.TYPE_BOMB:
			PlayZhadan (callback);
			break;

		default:
			callback ();
			break;
		}
	}
}